import os
import pandas as pd

def calculate_mean_avg(input_folder,output_file):

    all_data=[]

    for filename in os.listdir(input_folder):
        if filename.endswith(".csv"):
            file_path=os.path.join(input_folder,filename)
            df=pd.read_csv(file_path,usecols=["FID_","MEAN"])
            all_data.append(df)

    combined_data=pd.concat(all_data,ignore_index=True)
    mean_avg=combined_data.groupby("FID_")["MEAN"].mean().reset_index()
    mean_avg.rename(columns={"MEAN":"SMCI_2020"},inplace=True)
    mean_avg.to_csv(output_file,index=False)


input_folder="D:\Lenovo\Desktop\云南大学\毕业设计\毕设数据\原始数据\SMCI V1.0\SMCI土壤湿度表\\2020"
output_file="D:\Lenovo\Desktop\云南大学\毕业设计\毕设数据\原始数据\SMCI V1.0\SMCI土壤湿度表\\2020\\SMCI_2020.csv"
calculate_mean_avg(input_folder,output_file)